package ro.one.gaeql.model;

import java.io.Serializable;

public class AssignExpression implements Serializable, Evaluable {
	private static final long serialVersionUID = 1L;
	
	Evaluable left;
	Evaluable right;
	AssignExpressionOperator op;
	
	Evaluable value;
	
	public AssignExpression(Evaluable value) {
		this.value = value;
	}
	
	public AssignExpression(Evaluable left, AssignExpressionOperator op, Evaluable right) {
		this.left = left;
		this.op = op;
		this.right = right;
	}
	
	public Object eval(EvalContext context) {
        if (value != null)
            return value.eval(context);

        Object leftValue = left.eval(context);
        Object rightValue = right.eval(context);

        OperatorEvaluator evaluator = OperatorEvaluatorFactory.CreateOperatorEvaluator(op);
        return evaluator.eval(leftValue, op, rightValue);
	}
}
